package com.dfrz.ch08.task;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 作者：wangmaokang
 * 日期: 2021/4/19 9:20
 * 描述:
 */
public class Demo01 {

    //中文字符正则表达式
    public static boolean charChinese(String ch){
        String str = "^[\\u4e00-\\u9fa5]*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
           return false;
        }else{
           return true;
        }
    }

    //双字节字符正则表达式
    public static void charDouble(String ch){
        String str = "[^\\x00-\\xff]";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是双字节字符");
        }else{
            System.out.println("是双字节字符");
        }
    }

    //空白字符正则表达式
    public static void charSpace(String ch){
        String str = "[\\s]*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是空白字符");
        }else{
            System.out.println("是空白字符");
        }
    }

    //Email地址正则表达式
    public static void charEmail(String ch){
        String str = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是Email地址");
        }else{
            System.out.println("是Email地址");
        }
    }

    //Url地址正则表达式
    public static void charUrl(String ch){
        String str = "[a-zA-z]+://[^\\s]*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是Url地址");
        }else{
            System.out.println("是Url地址");
        }
    }

    //手机号码正则表达式
    public static void charTel(String ch){
        String str = "^[1][3,4,5,7,8][0-9]{9}";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是手机号码");
        }else{
            System.out.println("是手机号码");
        }
    }

    //固定电话正则表达式
    public static void charPhone(String ch){
        String str = "^(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{7,14}";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是电话号码");
        }else{
            System.out.println("是电话号码");
        }
    }

    //负浮点数正则表达式
    public static void charPoint(String ch){
        String str = "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是负浮点数");
        }else{
            System.out.println("是负浮点数");
        }
    }

    //整数正则表达式
    public static void charPositive(String ch){
        String str = "-?[1-9]\\d*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是整数");
        }else{
            System.out.println("是整数");
        }
    }

    //正浮点数正则表达式
    public static void charFloating(String ch){
        String str = "^\\d+(\\.\\d+)?";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是正浮点数");
        }else{
            System.out.println("是正浮点数");
        }
    }

    //qq号正则表达式
    public static void charQq(String ch){
        String str = "^[1-9][0-9]{4,10}";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是qq号");
        }else{
            System.out.println("是qq号");
        }
    }

    //邮编号正则表达式
    public static void charPostal(String ch){
        String str = "[1-9]\\d{5}(?!\\d)";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是邮编号");
        }else{
            System.out.println("是邮编号");
        }
    }

    //IP地址正则表达式
    public static void charIp(String ch){
        String str = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是IP地址");
        }else{
            System.out.println("是IP地址");
        }
    }

    //身份证号码正则表达式
    public static void charId(String ch){
        String str = "\\d{17}[\\d|x]|\\d{15}";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是身份证号码");
        }else{
            System.out.println("是身份证号码");
        }
    }
    //格式日期正则表达式
    public static void charDay(String ch){
        String str = "\\d{4}(\\-|\\/|.)\\d{1,2}\\1\\d{1,2}";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是格式日期");
        }else{
            System.out.println("是格式日期");
        }
    }

    //正整数正则表达式
    public static void charZheng(String ch){
        String str = "[1-9]\\d*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是正整数");
        }else{
            System.out.println("是正整数");
        }
    }

    //负整数正则表达式
    public static void charFu(String ch){
        String str = "-[1-9]\\d*";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是负整数");
        }else{
            System.out.println("是负整数");
        }
    }

    //用户名正则表达式
    public static void charName(String ch){
        String str = "[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+";
        Pattern pattern = Pattern.compile(str);
        Matcher m = pattern.matcher(ch);
        if(!m.matches()){
            System.out.println("不是用户名");
        }else{
            System.out.println("是用户名");
        }
    }
}